
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="xms">
    <meta name="author" content="xms">
    <link rel="icon" href="/content/favicon.ico">

    <title>自定义 - 实体 - 表单</title>

    <!-- Bootstrap core CSS -->
    <link href="/content/css/bootstrap3.3.5/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="/content/css/dashboard.css" rel="stylesheet">
    <link href="/content/css/font-awesome.min.css" rel="stylesheet">
    <link href="/content/customize/css/common.css" rel="stylesheet">
    <link href="/content/js/jquery-toast/jquery.toast.min.css" rel="stylesheet">
    <link id="themeLink" href="/content/css/theme/default.css" rel="stylesheet" />
    <!-- Bootstrap core JavaScript ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="/content/js/jquery.min.js"></script>
    <script src="/content/js/bootstrap.min.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="/content/js/ie10-viewport-bug-workaround.js"></script>
    <script src="/content/js/jquery.bootstrap.min.js"></script>
    <script src="/content/js/json2.js"></script>
    <script src="/content/js/xms.utility.js"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.core.js"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.widget.js"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.mouse.js"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.draggable.js"></script>
    <script src="/content/js/jquery-toast/jquery.toast.min.js"></script>
    <script src="/content/js/xms.jquery.js"></script>
    <script src="/content/js/xms.web.js"></script>
    <script src="/content/js/xms.metadata.js"></script>
    <script src="/content/js/md5.js" type="text/javascript"></script>
    <script src="/content/js/commonlabels.js"></script>
    <script src="/content/js/common/pagecontext.js"></script>
    <script src="/api/user/usercontext"></script>
    <script>
        jQuery(function () {
            Xms.Web.Loading();
            function aLinkClick(e) {

                if (currentKeycode != 17 && window.parent && window.parent.addToTab) {
                    e.preventDefault();
                    var tabNav = $('#customTabNav', parent.document).children('.iframe-link-linkitem.active');
                    var textEl = tabNav.clone();
                    $(".glyphicon-remove", textEl).remove();
                    var label = textEl.text();
                    textEl = $(this).clone();
                    $("span", textEl).remove();
                    label = label + '-' + textEl.text();
                    var link = $(this).attr("href");
                    var id = $.md5(link);
                    Xms.Web.callParentMethod('addToTab', { id: id, label: label, link: link });
                    return false;
                } else {
                    //  currentKeycode = -99999;
                    //  var link = $(this).attr("href");
                    //  Xms.Web.OpenWindow(link);
                }

            }
            var currentKeycode = -99999;
            $("body").on("click.customizeLinkclick", 'a[href]a:not([href^="javascript:"])a:not([href^="#"])', function (e) {
                aLinkClick.call(this, e);
            });
        });
    </script>
    <link href="/content/customize/css/common.css" rel="stylesheet">
    <link href="/content/js/jquery-ui-1.10.3/themes/base/jquery.ui.all.css" rel="stylesheet">
    <link href="/content/js/grid/pqgrid.dev.css" rel="stylesheet">
    <style>
        body {
            padding: 0;
            margin: 0;
        }

        .table-responsive {
            max-height: 400px;
            overflow-y: auto;
        }

        .panel-default .panel-heading {
            background-color: white;
        }
    </style>
</head>
<body>
<div class="" id="body">
    <div class="clearfix">
        <div class="col-md-12" id="main">
            <div class="" style="padding:5px;" id="renderBody">
                <!--main-->

                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            <a data-toggle="collapse"
                               href="#collapseTwo">
                                <strong>表单</strong>
                            </a>
                        </h3>
                    </div>
                    <div id="collapseTwo" class="panel-collapse collapse in">
                        <div class="panel-body">
                            <div id="gridview">
                                <div class="mb-2 toolbar">
                                    <form action="/xms/api/systemform/list" method="get" id="searchForm" role="form">
                                        <input data-val="true" id="entityid" name="entityid" type="hidden" />
                                        <div class="row">
                                            <div class="col-sm-8">
                                                <div class="btn-group btn-group-sm">
                                                    <a class="btn btn-info btn-with-params" href="/xms/customize/systemform/create" target="_blank"><span class="glyphicon glyphicon-plus-sign"></span> 新增</a>
                                                    <button type="button" class="btn btn-warning" data-action="/api/schema/form/deletebyid" data-role="delete" data-tooltip="删除后不可恢复，请提前备份数据"><span class="glyphicon glyphicon-trash"></span> 批量删除</button>
                                                    <button type="button" class="btn btn-default btn-with-params" data-action="/api/schema/form/setdefault?isdefault=true" data-actiondata='{"isdefault":true}' data-role="update"><span class="glyphicon glyphicon-check"></span> 设为默认</button>
                                                    <button type="button" class="btn btn-default btn-with-params" data-action="/api/schema/form/setstate?isenabled=true" data-actiondata='{"isenabled":true}' data-role="update"><span class="glyphicon glyphicon-ok-circle"></span> 启用</button>
                                                    <button type="button" class="btn btn-default btn-with-params" data-action="/api/schema/form/setstate?isenabled=false" data-actiondata='{"isenabled":false}' data-role="update"><span class="glyphicon glyphicon-ban-circle"></span> 禁用</button>
                                                </div>
                                            </div>
                                            <div class="col-sm-4">
                                                <div class="input-group input-group-sm">
                                                    <input class="form-control" name="Name" placeholder="名称" type="text" />
                                                    <span class="input-group-btn">
                                        <button type="submit" class="btn btn-info btn-block grid-searcher"><span class="glyphicon glyphicon-search"></span> 查询</button>
                                    </span>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>

                                <div class="table-datagrid-view">
                                    <div class="datagrid-view"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- （Modal） -->
                <div class="modal fade" id="copyModal" tabindex="-1" role="dialog"
                     aria-labelledby="copyModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal"
                                        aria-hidden="true">
                                    ×
                                </button>
                                <h4 class="modal-title" id="navGroupModalLabel">
                                    复制表单
                                </h4>
                            </div>
                            <div class="modal-body">
                                <form id="copyForm" data-jsonajax="true" action="/xms/customize/systemform/copyform" method="post" class="form-horizontal">
                                    <input name="systemformid" type="hidden" />
                                    <div class="form-group row">
                                        <label for="" class="col-sm-2 col-md-2 col-xs-2  control-label">名称</label>
                                        <div class="col-sm-10 col-md-10 col-xs-10">
                                            <input id="name" name="name" type="text" class="form-control input-sm required" />
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default"
                                        data-dismiss="modal">
                                    <span class="glyphicon glyphicon-remove"></span> 取消
                                </button>
                                <button type="button" class="btn btn-primary" onclick="CopyPost()">
                                    <span class="glyphicon glyphicon-ok"></span> 确定
                                </button>
                            </div>
                        </div><!-- /.modal-content -->
                    </div><!-- /.modal-dialog -->
                </div><!-- /.modal -->


            </div>
            <nav class="navbar navbar-default navbar-fixed-bottom hide" role="navigation" id="body-footer">
                <div class="container">
                    <div class="navbar-form navbar-right" id="body-footer-content">
                    </div>
                </div>
            </nav>
        </div>
    </div>
</div>

<script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.button.js"></script>
<script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.mouse.js"></script>
<script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.autocomplete.js"></script>
<script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.draggable.js"></script>
<script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.resizable.js"></script>
<script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.tooltip.js"></script>
<script src="/content/js/fetch.js"></script>
<script src="/content/js/common/filters.js"></script>
<script src="/content/js/grid/pqgrid.dev.js"></script>
<script src="/content/js/grid/localize/pq-localize-zh.js"></script>
<script src="/content/js/cdatagrid.js"></script>
<script src="/content/js/jquery.bootpag.min.js"></script>
<script src="/content/js/jquery.form.js"></script>
<script src="/content/js/jquery-validate/jquery.validate.min.js"></script>
<script>
    var model = $.urlParamObj(location.href);
    var pageUrl = '';
    var solutionid = '';
    $(function () {
        $('#entityid').val(model.entityid);
        $('.btn-with-params').each(function(){
            var _this = $(this);
            if(_this.attr('type') == 'button'){
                var url = _this.attr('data-action');
                url += (url.indexOf('?') > 0 ? "&" : "?");
                _this.attr('data-action', url + 'entityid=' + model.entityid);
            }
            else {
                var url = _this.attr('href');
                url += (url.indexOf('?') > 0 ? "&" : "?");
                _this.attr('href', url + 'entityid=' + model.entityid);
            }
        });
        var theaders = {
            'name': '名称',
            'default': '默认',
            'statecode': '状态',
            'createdon': '创建时间',
            'operation':'操作'
        }
        //列数据配置数据
        var columnConfigs = [
            //从新配置复选框列的渲染方式，
            {
                title: "", dataIndx: "recordid", maxWidth: 48, minWidth: 48, align: "center", resizable: false,
                type: 'checkBoxSelection', cls: 'ui-state-default', sortable: false, editable: false,
                render: function (ui) {
                    //  console.log(ui)
                    return '<input type="checkbox" value="' + ui.rowData.systemformid + '" name="recordid" class="">'
                },
                cb: { all: true, header: true }
            },
            {
                title: "", dataIndx: "hidden", maxWidth: 30, minWidth: 30, align: "center", resizable: false,
                cls: 'ui-state-default', sortable: false, editable: false,
                hidden:true,
                render: function (ui) {
                    //  console.log(ui)
                    return '<input type="hidden" value="' + ui.rowData.systemformid + '" name="componenttypename" class="">'
                },
                cb: { all: true, header: true }
            },
            { "dataIndx": "name", "title": theaders.name, editable: false, "dataType": "string", "width": 250, "isprimaryfield": false, "attributetypename": "string" },
            { "dataIndx": "isdefault", "title": theaders.default, "dataType": "string", editable: false, "width": 150, "isprimaryfield": false, "attributetypename": "string" , render: function (ui, a, b) {
                    var datas = ui.rowData;
                    var dataIndx = ui.dataIndx;
                    var column = ui.column;
                    var recordid = datas[dataIndx];

                    if (recordid == true) {
                        return '<span class="label label-success">是</span>'
                    } else {
                        return '<span class="label label-default">否</span>'
                    }
                }},

            { "dataIndx": "statecode", "title": theaders.statecode, editable: false, "dataType": "string", "width": 100, "isprimaryfield": false, "attributetypename": "string", render: function (ui, a, b) {
                    var datas = ui.rowData;
                    var dataIndx = ui.dataIndx;
                    var column = ui.column;
                    var recordid = datas[dataIndx];

                    if (recordid == true) {
                        return '<span class="label label-success">启用</span>'
                    } else {
                        return '<span class="label label-default">禁用</span>'
                    }
                } },
            { "dataIndx": "createdon", "title": theaders.createdon, editable: false, "dataType": "string", "width": 150, "isprimaryfield": false, "attributetypename": "string" },
            {
                title: "操作", editable: false, minWidth: 200,width:200, notHeaderFilter: true, editable: false, sortable: false, render: function (ui) {
                    var datas = ui.rowData;
                    var dataIndx = ui.dataIndx;
                    var column = ui.column;
                    var recordid = datas[dataIndx];
                    var html = ''
                    html= '<a class="btn btn-info btn-xs" href="/xms/entity/create?entityid='+datas.entityid+'&formid='+datas.systemformid+'" target="_blank"><span class="glyphicon glyphicon-play-circle"></span> 预览</a>'+
                        ' <a class="btn btn-default btn-xs" href="/xms/customize/systemform/edit?id='+datas.systemformid+'" target="_blank"><span class="glyphicon glyphicon-edit"></span> 编辑</a>';
                        //+' <a class="btn btn-default btn-xs" href="javascript:CopyRecord(\'' + datas.systemformid + '\')"><span class="glyphicon glyphicon-file"></span> 复制</a>'
                        // +' <a class="btn btn-default btn-xs" href=\'javascript:CustomButtons(\"' + datas.systemformid + '\",\"' + datas.entityid + '\",' + (datas.iscustombutton ? true : false) + ',' + (datas.custombuttons ? JSON.stringify(datas.custombuttons) : '') + ')\'><span class="glyphicon glyphicon-flash"></span> 按钮</a>';
                    if (!datas.isdefault) {
                        html+= ' <a class="btn btn-warning btn-xs" href="javascript:Xms.Web.Del(\''+datas.systemformid+'\',\'/api/schema/form/deletebyid\',false,rebind,null,\'确定删除？请提前备份数据\',true)"><span class="glyphicon glyphicon-trash"></span> 删除</a>'
                    }

                    return html
                }
            }
        ];
        var url = ORG_SERVERURL + '/api/schema/form/list?LoadData=true&';
        var $form = $('#searchForm');
        var roles_filters = new XmsFilter();
        var datagridconfig = {
            scrollModel: { autoFit: true },
            baseUrl: url,
            columnConfigs: columnConfigs,//字段配置信息
            context: $('#gridview'),//底部操作按钮方法触发
            filters: roles_filters,//post提交时过滤条件
            searchForm: $form//GET提交时查询的数据
        };
        $('.datagrid-view').xmsDataTable(datagridconfig);
        Xms.Web.Form($('#copyForm'), function (response) {
            if (response.IsSuccess) {
                Xms.Web.Toast(response.Content, true);
                $('#copyModal').modal('hide');
                //location.reload(true);
                rebind();
                return;
            }
            Xms.Web.Alert(false, response.Content);
        });

        Xms.Web.Event.localStorageEvent.on('list_form_rebind', function () {
            setTimeout(function () {
                location.reload();
            },100)
        });
    });
    function rebind() {
        $('.datagrid-view').cDatagrid('refreshDataAndView')
    }
    function CopyRecord(id) {
        $('#copyForm').find('input[name=systemformid]').val(id);
        $('#copyModal').modal('show');
    }
    function CopyPost() {

        $('#copyForm').submit();
    }
    function CustomButtons(id, entityid, flag, buttons) {
        if (buttons) {
            var custombuttons = buttons ? JSON.parse(buttons) : null;
        } else {
            custombuttons = null;
        }
        console.log(custombuttons)
        var d = { entityid: entityid, objectid: id, iscustombutton: flag, custombuttons: custombuttons, buttonarea: 'form' };
        Xms.Web.OpenDialog('/customize/ribbonbutton/dialog', 'CustomButtons_Callback', d);
    }
    function CustomButtons_Callback(result, inputid) {
        console.log(result);
        var custombuttons = [];
        if (result.iscustombutton) {
            $(result.custombuttons).each(function (i, n) {
                custombuttons.push(n.id);
            });
        }
        Xms.Web.Post('/customize/systemform/SetFormButtons', { recordid: result.objectid, iscustombutton: result.iscustombutton, buttons: custombuttons },false, function (response) {
            if (response.IsSuccess) {
                //    Xms.Web.Toast(response.Content, true);
                rebind();
                return;
            }
            Xms.Web.Alert(false, response.Content);
            // rebind();
        });
    }
</script>

</body>
</html>